<template>
  <div class="login-container">
    <div class="box">
      <img src="@/components/images/建立管理单页.png" alt="">
      <h1>塘汛信息技术有限公司</h1>
      <!-- 输入框 -->
      <div class="inputBox">
        <h1>塘汛信息技术有限公司</h1>
        <h2>登录</h2>
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
          <el-form-item class="elInput" prop="number">
            <span class="svg-container">
              <svg-icon icon-class="home-filling" />
            </span>
            <el-input v-model="ruleForm.username" placeholder="请输入账号" />
          </el-form-item>

          <el-form-item class="elInput" prop="password">
            <span class="svg-container">
              <svg-icon icon-class="home-filling" />
            </span>
            <el-input v-model="ruleForm.password" placeholder="请输入密码" @keyup.enter.native="submitForm" />
          </el-form-item>
          <el-button class="buttons" type="primary" @click.native.prevent="handleLogin">登录</el-button>

        </el-form>
      </div>
    </div>

  </div>
</template>

<script>
import { postLogin } from '@/api/loginApi'
import { validMobile } from '@/utils/validate'

export default {
  data() {
    const validateMobile = (rule, value, callback) => {
      if (!validMobile(value)) {
        callback(new Error('请输入正确的手机号'))
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        username: '13403233136',
        password: '123456'
      },
      rules: {
        username: [{ required: true, trigger: 'blur', validator: validateMobile }],
        password: [
          { required: true, trigger: 'blur', message: '密码不能少' },
          { min: 6, max: 16, trigger: 'blur', message: '密码长度6-16位' }
        ]
      }
    }
  },
  methods: {

    // async dologin() {
    //   const res = await getListJianli(this.ruleForm)
    //   console.log('接口是', res)
    // },
    // submitForm() {
    //   alert('点击了登录')
    //   // this.loageGetListJianli()
    // },
    // async dologin() {
    //   try {
    //     const res = await postLogin(this.ruleForm)
    //     console.log('res', res)
    //   } catch (err) {
    //     alert('失败')
    //   }
    // },
    handleLogin() {
      this.$router.push('/')
      const res = postLogin(this.ruleForm)
      console.log('rest', res)
      // 手动兜底校验
      // this.$refs.ruleForm.validate(async valid => {
      //   if (valid) {
      //     // this.dologin()
      //     const res = await postLogin(this.ruleForm)
      //     console.log('res', res)

      //     // alert('通过校验')
      //     // login(this.loginForm)
      //     // this.loading = true
      //     // this.$store.dispatch('user/login', this.loginForm).then(() => {
      //     // this.$router.push({ path: this.redirect || '/' })
      //     //   this.loading = false
      //     // }).catch(() => {
      //     //   this.loading = false
      //     // })
      //   } else {
      //     console.log('error submit!!')
      //     return false
      //   }
      // })
    }
    // submitForm(formName) {
    //   this.$refs[formName].validate((valid) => {
    //     if (valid) {
    //       alert('submit!')
    //     } else {
    //       console.log('error submit!!')
    //       return false
    //     }
    //   })
    // },
    // resetForm(formName) {
    //   this.$refs[formName].resetFields()
    // }
  }
}
</script>

<style lang="scss">
.home-filling {
  size: 38px;
}
.box h2 {
  position: fixed;
  right: 236px;
  top: 115px;
  font-weight: lighter;
  color: blue;
}
.box h1 {
  position: fixed;
  right: 103px;
  top: 30px;
  font-weight: lighter;
  color: #9f9e9e;
}
.box .inputBox .buttons {
  width: 450px;
  height: 53px;
}
.box .inputBox .elInput {
  width: 450px;
  height: 59px;
  background-color: transparent;
  border: 1px solid #f2f2f2;

}
.box .inputBox {
  position: fixed;
  right: 36px;
  top: 209px;
  background-color: transparent;
}
.box img {
  position: fixed;
  left: 0;
  width: 50%;
  height: 100%;
  // text-align: left;
}
body {
  position: relative;
  width: 100%;
  height: 100%;

}
.box {
  display: flex;
  position:absolute;
  width: 1071px;
  height: 579px;
  background-color: #fff;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
}
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
    // color: #000;
    margin-left: -58px;
  }
}

/* reset element-ui css */
.login-container {
   background-image: url('~@/components/images/5d67d35a92e1a.jpg'); // 设置背景图片
   background-position: center; // 将图片位置设置为充满整个屏幕
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #000;
      height: 47px;
      // caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
